<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>添加联程(录入)addConnectflight.html</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		body{
			background:#f1f1f1;
			padding-bottom:20px;
		}
		.title{
			height:45px;
			line-height:45px;
			margin-left:4px;
			font-size:14px;
			font-weight:900;
			width:1032px;
		}
		.quare{
			margin:0 7px 0 11px;
			position:relative;
			top:3px;
			display:inline-block;
			width:16px;
			height:16px;
			background:url(../img/flightManage/addConnectflight.png) no-repeat;
		}
		.lkcp{
			margin:0 7px 0 11px;
			position:relative;
			top:3px;
			display:inline-block;
			width:17px;
			height:14px;
			background:url(../img/flightManage/paTicked.png) no-repeat;
		}
		.pjzf_title{
			margin:0 7px 0 11px;
			position:relative;
			top:3px;
			display:inline-block;
			width:17px;
			height:17px;
			background:url(../img/flightManage/pjzf.png) no-repeat;
		}
		.contentBox{
			width:1032px;
			background:white;
			margin-left:14px;
		}
		.times{
			line-height:40px;
			margin-left:20px;
		}
		.content{
			padding-bottom:20px;
			padding-top:20px;
		}
		.content table{
			width:990px;
			margin-left:20px;
		}
		.content table th,td{
			height:30px;
			border:1px solid #e7e7e7;
		}
		.content table th{
			background:#f1f1f1;
		}
		.backButton{
			text-align:center;
			padding:20px 0 ;
		}
		.peopleTotal{
			display:inline-block;
			margin-left:20px;
			font-weight:normal;
		}
		.peopleTotal span{
			color:red;
		}
		.head{
			line-height:45px;
	
		}
		.btnBox{
		
			text-align:center;
			margin-top:15px;
		}
		.cancel{
		background:#afb1b0;
		margin-left:10px;
		}
		table tbody input{
			font-family:"微软雅黑";
			width:100%;
			height:100%;
			border:none;
			text-align:center;
			outline:none;
		}
		.departureDate,.arriveAirportDate{
			text-align:left;
			margin-left:4px;
		}
	</style>
	<body>
	
		<p class='title'>
			<span><i class='quare'></i>联程航班</span>
		</p>
		<div class='contentBox'>
			<div class='content'>
				<table class="connectFlight">
					<tr>
						<th style="width:30px;">序号</th>
						<th>出发</th>
						<th>出发航站楼</th>
						<th>到达</th>
						<th>到达航站楼</th>
						<th>航班号</th>
						<th>舱位</th>
						 <th>机型</th> 
						<th>出发日期</th>
						<th>出发时间</th>
						<th>到达日期</th>
						<th>到达时间</th>
					</tr>
					<tbody class="clear">
						<tr>
							<td class="index">1</td>
							<td><input limit="haveTo" type="text" class="departureAirportCode autocomplete"></td>
							<td><input type="text" class="departureAirportTerminal"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportCode autocomplete"></td>
							<td><input type="text" class="arriveAirportTerminal"></td>
							<td><input limit="haveTo" type="text" class="flightNumber"></td>
							<td><input limit="haveTo" type="text" class="seatClass"></td>
							<td><input type="text" class="aircraft"></td>
							<td><input limit="haveTo" type="text" class="departureDate datespicker" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
							<td><input limit="haveTo" type="text" class="departureTime datespicker" onclick="new WdatePicker({dateFmt:'HH:mm'})"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportDate datespicker" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportTime datespicker" onclick="new WdatePicker({dateFmt:'HH:mm'})"></td>
						</tr>
						<tr>
							<td class="index">2</td>
							<td><input limit="haveTo" type="text" class="departureAirportCode autocomplete"></td>
							<td><input type="text" class="departureAirportTerminal"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportCode autocomplete"></td>
							<td><input type="text" class="arriveAirportTerminal" ></td>
							<td><input limit="haveTo" type="text" class="flightNumber"></td>
							<td><input limit="haveTo" type="text" class="seatClass"></td>
							<td><input type="text" class="aircraft"></td>
							<td><input limit="haveTo" type="text" class="departureDate datespicker" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
							<td><input limit="haveTo" type="text" class="departureTime datespicker" onclick="new WdatePicker({dateFmt:'HH:mm'})"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportDate datespicker" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
							<td><input limit="haveTo" type="text" class="arriveAirportTime datespicker" onclick="new WdatePicker({dateFmt:'HH:mm'})"></td>
						</tr>
					</tbody>
				</table>
			</div>
			
			<!-- 分页功能没未有添加 -->
		</div>
		<p class='title'>
			<span><i class='lkcp'></i>旅客与出票信息</span>
		</p>
		<div class='contentBox'>
			<div class='content' style='padding-top:20px;'>
				<table>
					<tr>	
						<th>成人</th>
						<th>儿童</th>
						<th>婴儿</th>
					</tr>
					<tbody class="clearPassenger">
						<tr>
							<td><input type="text"  class="adultPassenger" value="0"></td>
							<td><input type="text"  class="childPassenger" value="0"></td>
							<td><input type="text"  class="infantPassenger" value="0"></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<p class='title'>
			<span><i class='pjzf_title'></i>票价与支付</span>
			<span class='peopleTotal'>总费用：<span id="audlt" class="totalPrice">0</span>元</span>
		</p>
		<div class='contentBox'>
			<div class='content' style='padding-top:20px;'>
				<table>
					<tr>
						<th>旅客类型</th>
						<th>票价</th>
						<th>税金</th>
						<th>总费用(单人)</th>
						<th>旅客人数</th>
						<th>总费用</th>						
					</tr>
					<tbody class="pjzf">
						<tr>
							<td>成人</td>
							<td><input type="text" class="adultPrice" value="0"></td>
							<td><input type="text" class="adultTFC" value="0"></td>
							<td class="adultSigleprice"></td>
							<td class="adultNum"></td>
							<td class="adultTotalprice"></td>
						</tr>
						<tr>
							<td>儿童</td>
							<td><input type="text" class="childPrice" value="0"></td>
							<td><input type="text" class="childTFC" value="0"></td>
							<td class="childSigleprice"></td>
							<td class="childNum"></td>
							<td class="childTotalprice"></td>
						</tr>
						<tr>
							<td>婴儿</td>
							<td><input type="text" class="infantPrice" value="0"></td>
							<td><input type="text" class="infantTFC" value="0"></td>
							<td class="infantSigleprice"></td>
							<td class="infantNum"></td>
							<td class="infantTotalprice"></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		 
		<div class='btnBox'>
			<button class='Dolo_btn sure'>确认</button>
			<button class='Dolo_btn cancel'>取消</button>
		</div>  
	</body>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../js/jquery.autocomplete.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
			<!-- 引入my97日期时间控件 -->
		<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js" charset="utf-8"></script>	
		<script type="text/javascript" src="../js/common.js" ></script>
		<script>
		$(".cancel").click(function(){
			closeWin();
		});
		 var url = document.location.href.toString();
		 var u = url.split("=");
		// alert(u[1]);// 获取通过URL向下一个页面传过来的id值
		//实现输入联动展示效果
		$(".adultPassenger").keyup(function(){
			$(".adultNum").text($(".adultPassenger").val()); //成人人数
		})
		$(".childPassenger").keyup(function(){
			$(".childNum").text($(".childPassenger").val()); //儿童人数
		})
		$(".infantPassenger").keyup(function(){
			$(".infantNum").text($(".infantPassenger").val()); //婴儿人数
		})
		
		//封装函数将如果是空""转化为数字0
		function emptyTransZero(n){
			if(n==""||n==undefined||isNaN(n)){
				return Number("0");
			}else{
				return Number(n);
			}
			
		}
		var adultSigleprice=0;//成人总费用(单人)
		$(".adultPrice,.adultTFC").keyup(function(){
			adultSigleprice=emptyTransZero($(".adultPrice").val())+emptyTransZero($(".adultTFC").val());
			$(".adultSigleprice").text(adultSigleprice.toFixed(2));
		})
		var childSigleprice=0;//儿童总费用(单人)
		$(".childPrice,.childTFC").keyup(function(){
			childSigleprice=emptyTransZero($(".childPrice").val())+emptyTransZero($(".childTFC").val());
			$(".childSigleprice").text(childSigleprice.toFixed(2));
		})
		var infantSigleprice=0;//婴儿总费用（单人）
		$(".infantPrice,.infantTFC").keyup(function(){
			infantSigleprice=emptyTransZero($(".infantPrice").val())+emptyTransZero($(".infantTFC").val());
			$(".infantSigleprice").text(infantSigleprice.toFixed(2));
			
		})
		
		var adultTotalprice=0;//成人总费用
		$(".adultPrice,.adultTFC,.adultPassenger").keyup(function(){
			adultTotalprice=emptyTransZero($(".adultPassenger").val())*(emptyTransZero($(".adultPrice").val())+emptyTransZero($(".adultTFC").val()));
			$(".adultTotalprice").text(adultTotalprice.toFixed(2));
		})
		var childTotalprice=0;//儿童总费用
		$(".childPrice,.childTFC,.childPassenger").keyup(function(){
			childTotalprice=emptyTransZero($(".childPassenger").val())*(emptyTransZero($(".childPrice").val())+emptyTransZero($(".childTFC").val()));
			$(".childTotalprice").text(childTotalprice.toFixed(2));
		})
		var infantTotalprice=0;//婴儿总费用
		$(".infantPrice,.infantTFC,.infantPassenger").keyup(function(){
			infantTotalprice=emptyTransZero($(".infantPassenger").val())*(emptyTransZero($(".infantPrice").val())+emptyTransZero($(".infantTFC").val()));
			$(".infantTotalprice").text(infantTotalprice.toFixed(2));
		})
		
		var totalPrice=0;//总费用
		$(".adultPrice,.adultTFC,.adultPassenger,.childPrice,.childTFC,.childPassenger,.infantPrice,.infantTFC,.infantPassenger").keyup(function(){
			totalPrice=emptyTransZero($(".adultPassenger").val())*(emptyTransZero($(".adultPrice").val())+emptyTransZero($(".adultTFC").val()))+
						emptyTransZero($(".childPassenger").val())*(emptyTransZero($(".childPrice").val())+emptyTransZero($(".childTFC").val()))+
						emptyTransZero($(".infantPassenger").val())*(emptyTransZero($(".infantPrice").val())+emptyTransZero($(".infantTFC").val()));
			$(".totalPrice").text(totalPrice.toFixed(2));
		})
		
		
		
		$(".sure").click(function(){
			//对联程航班表格的input输入框做不能为空的验证
		/* 	 var length_flight = $(".clear input[type=text]").length;
			for(var i=0;i<length_flight;i++){
				if($(".clear input[type=text]").eq(i).val()==""){
					layer.msg("请将联程航班表格输入完整的信息",{icon: 2,time:1000})
					return false;
				}
			} */
			var length_flight = $(".clear input[limit=haveTo]").length;
			for(var i=0;i<length_flight;i++){
				if($(".clear input[limit=haveTo]").eq(i).val()==""){
					layer.msg("请将联程航班表格输入完整的信息",{icon: 2,time:1000})
					return false;
				}
			}
			
			
			 //对旅客与出票信息表格的input输入框做不能为空的验证
			 var length_passenger = $(".clearPassenger input[type=text]").length;
				for(var i=0;i<length_passenger;i++){
					if($(".clearPassenger input[type=text]").eq(i).val()==""){
						layer.msg("旅客与出票信息表格输入不能为空",{icon: 2,time:1000})
						return false;
					}
				}
				
				 //对票价与支付的input输入框做不能为空的验证
				 var length_pjzf = $(".pjzf input[type=text]").length;
					for(var i=0;i<length_pjzf;i++){
						if($(".pjzf input[type=text]").eq(i).val()==""){
							layer.msg("票价与税金输入不能为空",{icon: 2,time:1000})
							return false;
						}
					}
			
					
			var json={};//初始化对象，用于存放外层传输的数据
			//获取联程航班表格的数据
			var len=$(".connectFlight>.clear>tr").length;
			var flightDataArr=[];//定义数组用于存放每条数据
			
			for(var i=0;i<len;i++){
				var json_flight={};
				json_flight.index=parseInt($(".index").eq(i).text());//序号
				if(/\((.)+?\)/.test($(".departureAirportCode").eq(i).val())){//获取出发机场三字码
					json_flight.departureAirportCode = $(".departureAirportCode").eq(i).val().slice(-5).split("(")[1].split(")")[0];
				}else{
					json_flight.departureAirportCode = $(".departureAirportCode").eq(i).val()
				}
				if(/\((.)+?\)/.test($(".arriveAirportCode").eq(i).val())){//获取到达机场三字码
					json_flight.arriveAirportCode = $(".arriveAirportCode").eq(i).val().slice(-5).split("(")[1].split(")")[0];
				}else{
					json_flight.arriveAirportCode = $(".arriveAirportCode").eq(i).val()
				}
				//json_flight.departureAirportCode=$(".departureAirportCode").eq(i).val();//出发
				//json_flight.arriveAirportCode=$(".arriveAirportCode").eq(i).val();//到达
				json_flight.flightNumber=$(".flightNumber").eq(i).val();//航班号
				json_flight.seatClass=$(".seatClass").eq(i).val();//舱位
				json_flight.aircraft=$(".aircraft").eq(i).val();//机型
				json_flight.departureDate=$(".departureDate").eq(i).val();//出发日期
				json_flight.departureTime=$(".departureTime").eq(i).val();//出发时间
				json_flight.arriveAirportDate=$(".arriveAirportDate").eq(i).val();//到达日期
				json_flight.arriveAirportTime=$(".arriveAirportTime").eq(i).val();//到达时间
				json_flight.departureAirportTerminal=$(".departureAirportTerminal").eq(i).val(); //出发航站楼
				json_flight.arriveAirportTerminal=$(".arriveAirportTerminal").eq(i).val(); //到达航站楼
				flightDataArr.push(json_flight);
			}
			json.itineraries=flightDataArr;//联程航班表格的数据
			json.adultPrice=$(".adultPrice").val();//成人票价
			json.childPrice=$(".childPrice").val();//儿童票价
			json.infantPrice=$(".infantPrice").val();//婴儿票价
			json.adultTFC=$(".adultTFC").val();//成人税金
			json.childTFC=$(".childTFC").val();//儿童税金
			json.infantTFC=$(".infantTFC").val();//婴儿税金
			json.adultPassengerNumber=$(".adultPassenger").val();//成人的数量
			json.childPassengerNumber=$(".childPassenger").val();//儿童的数量
			json.infantPassengerNumber=$(".infantPassenger").val();//婴儿的数量			
			layer.msg('提交中...', {icon: 16,shade: 0.01});			
			//将得到的数据传输给服务器端
			 $.ajax({
					type:"post",
					url:"../order/"+u[1]+"/createConnectOrder?temp="+Math.random(),
					contentType:'application/json;charset=utf-8',
					data:JSON.stringify(json),
					async:true,
					success:function(data){
						var data=JSON.parse(data);
						
						if(data.status.toString()=="1001"){
							layer.msg(data.message, {icon: 1,time:1000},function(){
								var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
								parent.layer.close(index);//关闭弹窗
							});			
						}else{							
							layer.msg(data.message, {icon: 2,time:1000})
						}
					}
				});
			
			
		});
//___________________________________________________________________________机场联想
		var autocompleteData=[];
		$.ajax({
			type:"get",
			url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
			dataType:"json",
			success:function(data){	
				autocompleteData = data.data.list; 
				$('.autocomplete').autocomplete({
				    lookup: autocompleteData,
				    autoSelectFirst:true,
				    onSelect: function (suggestion) {	
				    	
				    }
				});
			}
		})		 	
//___________________________________________________________________________机型联想		
		var aircftAutocompleteData=[];
		$.ajax({
			type:"get",
			url:"../Aircft?pageSize=100000&pageNum=1&temp="+Math.random(),
			dataType:"json",
			success:function(data){	
				aircftAutocompleteData = data.data.list; 
				$('.aircraft').autocomplete({
				    lookup: aircftAutocompleteData,
				    autoSelectFirst:true,
				    onSelect: function (suggestion) {		   
				    }
				});
			}
		})
	 
		
		
		</script>		
</html>
